package controllers;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import models.CoreTable;
import models.User;
import play.db.jpa.JPABase;
import play.mvc.Controller;
import play.mvc.With;
import utils.Paged;

@With(AuthorityFilter.class)
public class BaseController extends Controller{
    
    protected static final int FIRST_PAGE = 1;
    
    protected static final int PAGE_SIZE = 10;
    
    protected static int getCurrentPage(int currentPage) {
        if (currentPage < 1) {
            return 1;
        }
        return currentPage;
    }
    
    
    protected static User getUser(long userid) {
        return User.findById(userid);
    }
    
    protected static boolean isExistUser(User user) {
        return null != user;
    }
    
    protected static String getCurrentUserid() {
         String userid = session.get("userid");
         if (userid == null) {
             notFound();
         }
         return userid;
    }
    
    protected static User getCurrentUser() {
        User current = User.findCurrentUser(getCurrentUserid());
        if (current == null) {
            notFound();
        }
        return current;
    }
    
}
